package com.yonyou.le.unattended.service;

import java.io.IOException;

import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.yonyou.le.unattended.entity.meta.CarInfoData;
import com.yonyou.le.unattended.websocket.MonitorUtils;
import com.yonyou.le.unattended.websocket.MsgTypeEnum;

@Component
public class WsMessageService {

	/**
	 * 调用ws服务，发送实时消息
	 * @param opCode
	 */
	public void sendCar(String opcode,CarInfoData cid){
		Gson gson = new Gson();
		try {
			MonitorUtils.sendMessage(MsgTypeEnum.WS_TYPE_CARINFO.getName(), opcode,
					gson.toJson(cid));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
	/**
	 * 调用ws服务，发送实时消息
	 * @param opCode
	 */
	public void sendMsg(String opcode,String msg){
		try {
			MonitorUtils.sendMessage(MsgTypeEnum.WS_TYPE_CARMSG.getName(), opcode, msg);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 调用ws服务，修改状态
	 * @param opCode
	 */
	public void changeState(String opcode,int status){
		try {
			MonitorUtils.sendMessage(MsgTypeEnum.WS_TYPE_CARSTATUS.getName(), opcode, status+"");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 调用ws服务，下个状态
	 * @param opCode
	 */
	public void nextState(String opcode){
		try {
			MonitorUtils.sendMessage(MsgTypeEnum.WS_TYPE_CARSTATUS.getName(), opcode, "99");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
